using System.Reflection;
using System.Resources;

namespace Framework.Library.Core.Utils.Resources
{
    public class ResourceLoader<TAssemblyMarker> : ResourceLoader
    {
        private static readonly object _sync;
        private static IResourceGetter _instance;

        static ResourceLoader()
        {
            _sync = new object();
        }

        protected ResourceLoader(Assembly resourceAssembly)
            : base(resourceAssembly)
        {
        }

        public static IResourceGetter ResourceGetterInstance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_sync)
                    {
                        if (_instance == null)
                            _instance = new ResourceLoader<TAssemblyMarker>(typeof (TAssemblyMarker).Assembly);
                    }
                }

                return _instance;
            }
        }

        public new static ResourceManager ResourceManager
        {
            get { return ResourceGetterInstance.ResourceManager; }
        }

        public new static string GetString(string name)
        {
            return ResourceGetterInstance.GetString(name);
        }

        public new static string GetString(string name, params object[] values)
        {
            return ResourceGetterInstance.GetString(name, values);
        }

        public new static object GetObject(string name)
        {
            return ResourceGetterInstance.GetObject(name);
        }

        public new static T GetObject<T>(string name)
        {
            return ResourceGetterInstance.GetObject<T>(name);
        }
    }
}